#ifndef VENUS_UI_GLUT_WINDOW_H
#define VENUS_UI_GLUT_WINDOW_H

#include "graphics/opengl.h"
#include "glh/glh_glut.h"
#include "logic_window.h"

namespace venus {
class GlutWindow : public LogicWindow {
public:
  GlutWindow(const char *title = "GlutWindow",
    int x = -1, int y = -1,
    int width = 800, int height = 600,
    unsigned int mode = GLUT_RGBA);

  virtual ~GlutWindow(void);	
  virtual bool Initialize() { return true; }
  static int Run() { glutMainLoop(); return 0; }
protected:
  void ReDraw() { glutPostRedisplay(); }
  void SetWindowSize(int width, int height) { 
    this->set_width(width); this->set_height(height);
    glutReshapeWindow(width, height); 
  }
private:
  static void button(int button, int state,int x, int y) {
    int id = glutGetWindow();
    s_windows[ id ]->OnMouse(button, state, x, y);
  }
  static void display() {
    int id = glutGetWindow();
    s_windows[ id ]->OnDisplay();
  }
  static void keyboard(unsigned char key, int x, int y) {
    int id = glutGetWindow();
    s_windows[ id ]->OnKeyboard(key, x, y);
  }
  static void specialkey(int key, int x, int y) {
    int id = glutGetWindow();
    s_windows[ id ]->OnSpecialKey(key, x, y);
  }
  static void idle() {
    int id = glutGetWindow();
    s_windows[ id ]->OnIdle();
  }
  static void reshape(int w, int h) {
    int id = glutGetWindow();
    s_windows[ id ]->OnResize(w, h);
  }
  static void motion(int x, int y) {
    int id = glutGetWindow();
    s_windows[ id ]->OnMouseMove(x, y);
  }
  static void passive_motion(int x, int y) {

  }
  static void timer(int millis) {

  }
  static void visibility(int state ){

  }
  static void menu_status(int state, int x, int y) {

  }

private:
  enum { kMaxGlutWindowCount = 100 };
  static GlutWindow* s_windows[kMaxGlutWindowCount];
  static bool s_glut_helper_initialized;
  int win_id_;
  glh::glut_callbacks call_backs_;
};
}

#endif//VENUS_UI_GLUT_WINDOW_H
